package zmee.pur.tnd.formplugin;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.RefObject;
import kd.bos.form.*;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.events.MessageBoxClosedEvent;
import kd.bos.form.operate.FormOperate;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: xw
 * @Date: 2022/11/29/15:00
 * @Description: 弹框提示确认
 */
public class TenderBillPlugin extends AbstractBillPlugIn {

    @Override
    public void beforeDoOperation(BeforeDoOperationEventArgs args) {
        super.beforeDoOperation(args);
        FormOperate source = (FormOperate) args.getSource();
        String operateKey = source.getOperateKey();
        if ("audit".equals(operateKey)) {
            RefObject<String> refObject = new RefObject<>();
            if (!source.getOption().tryGetVariableValue("afterconfirm", refObject)) {
                MessageBoxOptions options = MessageBoxOptions.OKCancel;
                ConfirmCallBackListener callBack = new ConfirmCallBackListener("tb", this);
                List<MessageBoxLink> msgLinks = new ArrayList<>();
                MessageBoxLink messageBoxLink = new MessageBoxLink();
                messageBoxLink.setText("压缩并加密");
                messageBoxLink.setUrl("");
                msgLinks.add(messageBoxLink);
                this.getView().showConfirm("请确认上传的投标文件已经#{0}", msgLinks, options, ConfirmTypes.Default, callBack);
                args.setCancel(true);
            }
        }
    }

    @Override
    public void confirmCallBack(MessageBoxClosedEvent evt) {
        super.confirmCallBack(evt);
        if ("tb".equals(evt.getCallBackId())) {
            if (MessageBoxResult.Yes.equals(evt.getResult())) {
                OperateOption operateOption = OperateOption.create();
                operateOption.setVariableValue("afterconfirm", "true");
                this.getView().invokeOperation("audit", operateOption);
            }
        }
    }
}
